package com.egao.common.module.recommendation.controller;


import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.recommendation.entity.RecommendationGraduateEmployment;
import com.egao.common.module.recommendation.entity.vo.RecommendationAuditParam;
import com.egao.common.module.recommendation.entity.vo.RecommendationListVo;
import com.egao.common.module.recommendation.service.IRecommendationGraduateEmploymentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ld
 * @since 2025-04-02
 */
@Api(tags = "管理")
@RestController
@RequestMapping("${api}")
public class RecommendationGraduateEmploymentController {
    private IRecommendationGraduateEmploymentService graduateEmploymentService;

    @Autowired
    public RecommendationGraduateEmploymentController(IRecommendationGraduateEmploymentService graduateEmploymentService){
        this.graduateEmploymentService = graduateEmploymentService;
    }

    @PreAuthorize("hasAuthority('recEmpl:list')")
    @ApiOperation("查询列表")
    @GetMapping("/recGraduateEmpl/list")
    public PageResult<RecommendationListVo> list(HttpServletRequest request){
        PageParam<RecommendationGraduateEmployment> page = new PageParam<>(request);
        return graduateEmploymentService.list(page);
    }

    @PreAuthorize("hasAuthority('recEmpl:read')")
    @ApiOperation("查询单个")
    @GetMapping("/recGraduateEmpl/read/{id}")
    public JsonResult read(@PathVariable("id") Integer id){
        return graduateEmploymentService.read(id);
    }

    @PreAuthorize("hasAuthority('recEmpl:my')")
    @ApiOperation("查询单个")
    @GetMapping("/recGraduateEmpl/my")
    public JsonResult read(){
        return graduateEmploymentService.read();
    }

    @PreAuthorize("hasAuthority('recEmpl:add')")
    @ApiOperation("添加推荐表")
    @PostMapping("/recGraduateEmpl/add")
    public JsonResult add(@RequestBody RecommendationGraduateEmployment model){
        return graduateEmploymentService.add(model);
    }

    @PreAuthorize("hasAuthority('recEmpl:submit')")
    @ApiOperation("提交推荐表")
    @PostMapping("/recGraduateEmpl/submit/{id}")
    public JsonResult submit(@PathVariable("id") Integer id){
        return graduateEmploymentService.submit(id);
    }

    @PreAuthorize("hasAuthority('recEmpl:update')")
    @ApiOperation("保存推荐表")
    @PostMapping("/recGraduateEmpl/update")
    public JsonResult update(@RequestBody RecommendationGraduateEmployment model){
        return graduateEmploymentService.update(model);
    }

    @PreAuthorize("hasAuthority('recEmpl:audit')")
    @ApiOperation("辅导员审核")
    @PostMapping("/recGraduateEmpl/audit")
    public JsonResult audit(@RequestBody RecommendationAuditParam param){
        return  graduateEmploymentService.audit(param);
    }

    @PreAuthorize("hasAuthority('recEmpl:delete')")
    @ApiOperation("删除就业推荐表记录")
    @GetMapping("/recGraduateEmpl/delete/{ids}")
    public JsonResult delete(@PathVariable("ids") Integer[] ids){
        return graduateEmploymentService.delete(ids);
    }

    @PreAuthorize("hasAuthority('recEmpl:export')")
    @ApiOperation("导出")
    @GetMapping("/recGraduateEmpl/export/{id}")
    public JsonResult export(@PathVariable("id") Integer id, HttpServletResponse response) throws IOException {
        return graduateEmploymentService.export(id, response);
    }
}

